﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using DevExpress.Xpf.Grid;
using DAL.BAL;

namespace WpfClient.Windows
{
    /// <summary>
    /// Interaction logic for BackUpOptions.xaml
    /// </summary>
    public partial class BackUpOptions : Window
    {
        public BackUpOptions()
        {
            InitializeComponent();

            gridControl1.ItemsSource = Business.GetBackupOptions();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;

            this.Close();
        }

        private void TableView_ValidateRow(object sender, DevExpress.Xpf.Grid.GridRowValidationEventArgs e)
        {
            e.IsValid = true;

            if (((DAL.Models.BackUpOption)e.Row).OptionName == "Время исполнения")
            {
                TimeSpan t = new TimeSpan();

                if (!TimeSpan.TryParse(((DAL.Models.BackUpOption)e.Row).Value, out t))
                {
                    e.ErrorContent = "Не правельное время";
                    e.ErrorType = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Warning;
                    e.IsValid = false;
                }
            }
                                    
        }

        private void TableView_InvalidRowException(object sender, DevExpress.Xpf.Grid.InvalidRowExceptionEventArgs e)
        {
            e.ExceptionMode = ExceptionMode.DisplayError;
        }
    }
}
